package com.zrrd._01_jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Scanner;

/**
 * @author WanJl
 * @version 1.0
 * @title TestConnection
 * @description
 * @create 2024/1/11 15:04
 */
public class TestConnection {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入ip地址：");
        String ip = sc.nextLine();
        System.out.println("请输入端口号：");
        String port = sc.nextLine();
        String url="jdbc:mysql://"+ip+":"+port+"/jms2301_db01";
        System.out.println("请输入用户名：");
        String username = sc.nextLine();
        System.out.println("请输入密码：");
        String password = sc.nextLine();

        Class.forName("com.mysql.cj.jdbc.Driver");  //com.mysql.cj.jdbc.Driver  就是包名.类名

        Connection conn = DriverManager.getConnection(url, username, password);
        if (conn!=null){
            System.out.println("连接成功..");
        }else {
            System.out.println("连接失败...");
        }
    }
}
